package day02;

/**
 * @Author Stringzhua
 * @Date 2024/10/29 11:55
 * description:
 */
public class Test1{
    public static void main(String[] args) throws InterruptedException {
        AddThread addThread = new AddThread();
        DecThread decThread = new DecThread();

        addThread.start();
        decThread.start();

        addThread.join();
        decThread.join();

        System.out.println(Count.count);
    }
}

class Count {
    public static final Object LOCK = new Object();
    public static int count = 0;
}

//递增线程
class AddThread extends Thread {
    @Override
    public void run() {
        synchronized (Count.LOCK){
            for (int i = 0; i < 1000; i++) {
                Count.count += 1;
            }
        }
    }
}

//递减线程
class DecThread extends Thread {
    @Override
    public void run() {
        synchronized (Count.LOCK){
            for (int i = 0; i < 1000; i++) {
                Count.count -= 1;
            }
        }
    }
}


